# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=flatpak
# Follows GNOME versioning, MINOR (the 2nd number) must be even.
pkgver=1.14.5
pkgrel=0
pkgdesc="Application deployment framework for desktop apps"
url="https://flatpak.org/"
arch="all"
license="LGPL-2.1-or-later"
depends="
	bubblewrap
	desktop-file-utils
	gtk-update-icon-cache
	shared-mime-info
	xdg-dbus-proxy
	"
makedepends="
	appstream-dev
	appstream-glib-dev
	bison
	curl-dev
	dconf-dev
	fuse3-dev
	glib-dev
	gpgme-dev
	json-glib-dev
	libarchive-dev
	libcap-dev
	libgcab-dev
	libseccomp-dev
	libxau-dev
	libxslt-dev
	ostree-dev>=2018.08
	polkit-dev
	py3-parsing
	zstd-dev
	"
checkdepends="bash"
subpackages="
	$pkgname-dbg
	$pkgname-lang
	$pkgname-dev
	$pkgname-libs
	$pkgname-bash-completion
	$pkgname-fish-completion:fishcomp
	$pkgname-zsh-completion
	"
install="flatpak.pre-install flatpak.pre-upgrade flatpak.post-install"
source="https://github.com/flatpak/flatpak/releases/download/$pkgver/flatpak-$pkgver.tar.xz
	modules-load.conf
	fusermount3.patch
	tzdir.patch
	"
options="!check" # test environment setup requires glibc layout (locales..)

# secfixes:
#   1.12.5-r0:
#     - CVE-2022-21682
#   1.12.3-r0:
#     - CVE-2021-43860
#   1.12.2-r0:
#     - CVE-2021-41133
#   1.10.1-r0:
#     - CVE-2021-21261
#   1.2.4-r0:
#     - CVE-2019-10063

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--libexecdir=/usr/lib/$pkgname \
		--disable-static \
		--disable-documentation \
		--with-curl \
		--with-priv-mode=none \
		--with-system-bubblewrap \
		--with-system-helper-user=flatpak \
		--with-system-dbus-proxy \
		--enable-gdm-env-file \
		--with-dbus-config-dir=/usr/share/dbus-1/system.d
	make
}

check() {
	make -k check
}

package() {
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"

	# Remove systemd-specific files.
	rm -rf usr/lib/systemd
	rm -rf usr/lib/sysusers.d

	install -Dm644 "$srcdir"/modules-load.conf usr/lib/modules-load.d/flatpak.conf
}

fishcomp() {
	default_fishcomp

	amove usr/share/fish/vendor_conf.d
}

sha512sums="
552deaaf3e6712a56f33698c20e6b8225c8893fe9a375af897fd99e19c487bf79b19c3e4ce3b00f3caf90020019ff67c628ca6a8f2ae1e6e01db397d2081ab2b  flatpak-1.14.5.tar.xz
57d23d2778556eafc3035e6be575bf95b4032f123b35f2b1657eff5e7496de253173edc657f90531ee58e25673f4f27a5cd1cc76b14a038edb244f104a231771  modules-load.conf
665dc6003360ea65ce391fe2283344d47c1dafc8f860a5ba410641c7ef54d0c68a63c41963843aeb0364b95df567a83cb80007db282bd284a0744aacced8f1d3  fusermount3.patch
4317f1ade5999c5a4e1392b074c32dae07858f79a2769fd7f207182cb514b446fc33b480676d9e8eeaf7f26461e340342a8a17494cfdc63f156c38b58852daf4  tzdir.patch
"
